{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# OvR 和 OvO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets\n",
    "\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data[:,:2] # 只取前2个特征\n",
    "y = iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection._split import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,\n          verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model.logistic import LogisticRegression\n",
    "\n",
    "# sk-learn中的LogisticRegression已经可以支持多分类任务\n",
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)\n",
    "\n",
    "# 从参数可知，默认使用OvR  ：multi_class='ovr'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.7232142857142857, 0.65789473684210531)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg.score(X_train, y_train),log_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from c6_logistic_regression.plot_utils import plot_decision_boundary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/seamonster/MachineLearningClassicAlgorithmEnv/lib/python3.6/site-packages/matplotlib/contour.py:967: UserWarning: The following kwargs were not used by contour: 'linewidth'\n  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3X2QXAWZ7/HvMy9mxskkMUJISKKJBepqeImkclFWBHW3NlFJrmDpLRWxdjd33dXFdV3uZdkLK7UUJd5yZWVLK+J1wd3rVQOXIBu2fIsKuEAloCEQRPZGTEJCkJBkEmZiZua5f3T3pKfTfc7pPn3O6dPn96lKMX1eup8+Mzxz5vSvnzZ3R0REul9P1gWIiEg61PBFRApCDV9EpCDU8EVECkINX0SkINTwRUQKInLDN7NeM3vUzO6ps+4KM3vezH5W/vdH7S1TRETi6mti2yuBHcCsBuu/6e4fj1+SiIgkIdIZvpktAt4F3JpsOSIikpSoZ/hfAK4ChgO2udTMLgSeAv7C3XfVbmBm64B1AEMzZpx35vz5TZYrIpKe3rmwf/SVWZcxza4nH/mNu5/ayr6hDd/M3g3sd/etZnZRg82+A3zD3Y+Z2X8FbgPeXruRu68H1gMsX7LEN19zTSs1i4gkbs4He7n58Q9lXcZJPrlyxjOt7hvlDP8C4BIzWw0MALPM7J/dfepIuPsLVdvfCtzUakEiIlm77dyPwONZV9F+oQ3f3a8GrgYon+F/urrZl5cvcPe95ZuXUHpxV0QkV2479yNZl5CoZlI605jZ9cAWd78b+HMzuwQYBw4AV7SnPBGR5HV7o69oquG7+4+AH5W/vrZq+dRfASKNbBoZ5IsHhtk33sv8vgk+MXeE1cOj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FhT030q6TP8C4BLzOxXwP8B3m5m/1yzzR5gMUD5T5fZJPtO3dCa3P0Fdz9WvnkrcF6C9VQec0/5v/uB/wusrNlk6jiVLSovy7QuT3+0xm5gt7s/VL69gVKzrZb2sQqtKYPjVLEKeMTdn6uzLpOfqaCaMjpO7wR2uvvz7n4cuBN4S802afep0Jpa6VOJNnx3v9rdF7n7Ekp/wv3Q3Wt/S90NfKT89WXlbRJ7N1iUmmquY14C7EiqnvLjDZnZcOVr4PeB2kmidwOXl5MV51P6E29v1nVZyqM13H0fsMvMKhMD3wE8UbNZqscqSk1pH6cq/4XGl05S/5kKqymj4/Rr4Hwze3n5sd/Byf/Pp9qnotTUUp9K8pXmmleUL6L86jtwPXBJ+esBSn/aPQ08DLymA2q6EXgc+DmwGXh9wnW8pvxYPy8/7jXl5X8C/En5awP+EfgP4DFgRQrHJ0pdH686Vg8Cb0mhrnOBLcA2Sn/yv6IDjlVYTVkcpyFKzXJ21bKsj1NYTakfp/LjfgZ4ktIJzdeBGVn3qQg1Nd2nNFpBRKQg9E5bEZGCUMMXESkINXwRkYJQwxcRKQg1fBGRglDDFxEpCDV8EZGC+P9tAYbcw7OBCQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10382e208>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出决策边界\n",
    "plot_decision_boundary(log_reg, axis=[4, 8.5, 1.5, 4.5])\n",
    "plt.scatter(X[y==0,0], X[y==0,1])\n",
    "plt.scatter(X[y==1,0], X[y==1,1])\n",
    "plt.scatter(X[y==2,0], X[y==2,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "默认是使用OvR，那么改为使用OvO试试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用OvO方式\n",
    "log_reg2 = LogisticRegression(multi_class='multinomial', solver='newton-cg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n          intercept_scaling=1, max_iter=100, multi_class='multinomial',\n          n_jobs=1, penalty='l2', random_state=None, solver='newton-cg',\n          tol=0.0001, verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg2.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.8214285714285714, 0.78947368421052633)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg2.score(X_train, y_train), log_reg2.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/seamonster/MachineLearningClassicAlgorithmEnv/lib/python3.6/site-packages/matplotlib/contour.py:967: UserWarning: The following kwargs were not used by contour: 'linewidth'\n  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3XuQnHWd7/H3d2ZCMk4mCQghIQmGLRAiWS6SykGyayG4lgQLOAIrp9CVLd2ou7hx3bPWYbEAOVKW5ZZrVrbUiOeIsscLgQMowQIPcMTkAJVwh0EXl0sIuQAhySQkIZP+nj+6ZzLTdD9Pdz/9ey7dn1dViunn+p1m8s0zT3/62+buiIhI5+vJugAREUmHGr6ISJdQwxcR6RJq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qmgDd/MPgJsdff1Ic/TjAZr+gUw391PAu7h4L/sIf2Ju78XOAf4GzN7fwrnbERcXY9Q/rX8ZODbwG2B6+kD3gt8x91PBXYD/y3wOeM0UlPazxMAZnYIcB5wcxrna0RMTak/T2Z2KOUr+GOAo4ABM/t46PO2oaam+1ToK/wlwHlm9gLwU+AsM6uez7oRmAdQ+dVlOmHfqRtbk7u/7u77Kg9vAE4LWM/oOTdW/rsV+N/A4qpNxp6nirmVZZnW5emP1ngZeNndH6o8XkW52Y6X9nMVW1MGz9Ooc4BH3H1LjXWZ/ExF1ZTR8/RB4Hl3f9Xd9wO3AmdUbZN2n4qtqZU+FbThu/sV7j7X3edT/hXuXnev/lfqDuCTla8vqmwT7N1gjdRUdR/zPGAoVD2V8w2Y2eDo18CHgOpJoncAf1FJVpxO+Ve8TVnXZSmP1nD3zcAGMxudGHg28EzVZqk+V43UlPbzNM5/of6tk9R/puJqyuh5egk43czeUTn32bz973yqfaqRmlrqUyFfaa56RflMKq++A9cC51W+nkL5V7vngIeBP8pBTV8DngYeB+4DTghcxx9VzvV45bxXVpZ/Fvhs5WsD/hX4A/AksCiF56eRui4f91w9CJyRQl2nAOuAJyj/yn9oDp6ruJqyeJ4GKDfL6eOWZf08xdWU+vNUOe9XgGcpX9D8GJicdZ9qoKam+5RGK4iIdAm901ZEpEuo4YuIdAk1fBGRLqGGLyLSJdTwRUS6hBq+iEiXUMMXEekS/x9IGG/ao18EWgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1093d42b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出决策边界\n",
    "plot_decision_boundary(log_reg2, axis=[4, 8.5, 1.5, 4.5])\n",
    "plt.scatter(X[y==0,0], X[y==0,1])\n",
    "plt.scatter(X[y==1,0], X[y==1,1])\n",
    "plt.scatter(X[y==2,0], X[y==2,1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可见使用OvO比使用OvR要更准确"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用所有数据及特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = iris.data\n",
    "y = iris.target\n",
    "X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=666)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.94736842105263153"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)\n",
    "log_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用OvO\n",
    "log_reg2 = LogisticRegression(multi_class='multinomial', solver='newton-cg')\n",
    "log_reg2.fit(X_train, y_train)\n",
    "log_reg2.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## sklearn封装了专门的OvO，OvR类来提供给2分类算法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.94736842105263153"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.multiclass import OneVsRestClassifier\n",
    "from sklearn.multiclass import OneVsOneClassifier\n",
    "\n",
    "# 直接把2分类器传进去\n",
    "ovr = OneVsRestClassifier(log_reg)\n",
    "ovr.fit(X_train, y_train)\n",
    "ovr.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ovo = OneVsOneClassifier(log_reg)\n",
    "ovo.fit(X_train, y_train)\n",
    "ovo.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
